
<?php
/**
 * Article model for default modun, remove insert update delete
 * Add filter by category funcion
 * @author Kha
 * 
 */
class Application_Models_Articles extends Zend_Db_Table_Abstract {
	protected $_name = 'news_article';
	protected $_primary = 'article_id';
	
	public function getMetadata()
	{
		if(empty($this->_metadata))
		{
			$this->_setupMetadata();
		}
		return $this->_metadata;
	}
	
	/**
	 * 
	 * Tim kiem mot dong trong bang
	 * @param Int $article_id
	 */
	public function _find($article_id) {
        try 
        {
            $row = parent::find($article_id)->current();
            return Utility_Converter::arrayToObject($row->toArray());
        }catch(Zend_Db_Exception $ex) 
        {
            throw $ex;
        }
	}
	
	/**
	 * 
	 * Fetch all article revisin of an article.
	 * @param  int $article_id
	 */
	public  function filterByCategory($category_id)
	{
		$where = parent::getAdapter()
					->quoteInto('category_id = ?', $category_id);
		$articles = parent::fetchAll($where);
		return $articles;
	}
}